<?php
class Profile {
	
	private $profileID;
	private $username;
	private $password;
	private $email;
	private $profilePic;
	private $status;
	private $firstName;
	private $lastName;
	private $user;
	
	public function __construct($username) {
		
		$profileData = DBUtils::getProfileData($username);
		$this->profileID = $profileData['profile_id'];
		$this->username = $profileData['user_name'];
		$this->password = $profileData['password'];
		$this->email = $profileData['email'];
		$this->profilePic = $profileData['profile_pic'];
		$this->status = $profileData['status'];
		$this->firstName = $profileData['first_name'];
		$this->lastName = $profileData['last_name'];
		$this->user = new User($profileData['profile_id']);
		
	}
	
	public function getUser() {
		
		return $this->user;
	}
	
	public function getProfileID() {
		
		return $this->profileID;
	}
	
	private function setUsername($username) {
		
		if($username == '' || $username == NULL) {
			
			throw new Exception("Username can't be empty.");
		}
		
		$this->username = $username;
	}
	
	public function getUsername() {
		
		return $this->username;
	}
	
	public function setPassword($password) {
		
		if($password == '' || $password == NULL) {
				
			throw new Exception("Password can't be empty.");
		}
		
		if(strlen($password) < 6) {
				
			throw new Exception("Password should be more than 6 symbols.");
		}
		
		if(strlen($password) > 20) {
		
			throw new Exception("Password should be no more than 20 symbols.");
		}
		$password = md5($password);
		DBUtils::setPassword($password, $this->profileID);
		$this->password = $password;
	}
	
	public function getPassword() {
		
		return $this->password;
	}
	
	private function setEmail($email) {
		
		if($email == '' || $email == NULL) {
		
			throw new Exception("Email can't be empty.");
		}
		
		DBUtils::setEmail($email, $this->profileID);
		$this->email = $email;
	}
	
	public function getEmail() {
		
		return $this->email;
	}
	
	public function setProfilePic($profilePic) {
		
		DBUtils::setProfilePic($profilePic, $this->profileID);
		$this->profilePic = $profilePic;
		
	}
	
	public function getProfilePic() {
		
		return $this->profilePic;
	}
	
	public function setStatus($status) {
		
		DBUtils::setStatus($status, $this->profileID);
		$this->status = $status;
	}
	
	public function getStatus() {
		
		return $this->status;
	}
	
	public function setFirstName($firstName) {
		
		DBUtils::setFirstName($firstName, $this->profileID);
		$this->firstName = $firstName;
	}
	
	public function getFirstName() {
		
		return $this->firstName;
	}
	
	public function setLastName($lastName) {
		
		DBUtils::setLastName($lastName, $this->profileID);
		$this->lastName = $lastName;
	}
	
	public function getLastName() {
		
		return $this->lastName;
	}
}